package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.TbProdMapper;
import com.bwie.pojo.TbBrand;
import com.bwie.pojo.TbProd;
import com.bwie.pojo.TbProdAtta;
import com.bwie.service.TbProdAttaService;
import com.bwie.mapper.TbProdAttaMapper;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 叶雨洁
* @description 针对表【tb_prod_atta(商品附件表)】的数据库操作Service实现
* @createDate 2025-07-19 10:27:06
*/
@Service
public class TbProdAttaServiceImpl extends ServiceImpl<TbProdAttaMapper, TbProdAtta>
    implements TbProdAttaService{

    @Autowired
    TbProdAttaMapper prodAttaMapper;

    @Autowired
    TbProdMapper prodMapper;
    @Override
    public R saveAtta(TbProdAtta tbProdAtta) {

        TbProd tbProd = prodMapper.selectById(tbProdAtta.getProdId());
         //判断商品是否存在
        if(tbProd==null){
            return R.ERROR(500,"商品不存在");
        }

        tbProdAtta.setAttaVideo(tbProdAtta.getAttaVideo());
        tbProdAtta.setCreateBy("admin");
        tbProdAtta.setCreateTime(new Date());

        prodAttaMapper.updateById(tbProdAtta);


        if(tbProdAtta.getAttaImages()!=null && tbProdAtta.getAttaImages().length()>0){
            tbProdAtta.setAttaImages(tbProdAtta.getAttaImages());
        }

        prodAttaMapper.insert(tbProdAtta);
        return R.OK();
    }
}




